import subprocess    
import re
def ping(domainName):
    p = subprocess.Popen(["ping.exe", domainName], 
                                             stdin = subprocess.PIPE, 
                                             stdout = subprocess.PIPE, 
                                             stderr = subprocess.PIPE, 
                                             shell = True)    

    out = p.stdout.read()
    print out
    regex = re.compile("Reply from (\d+.\d+.\d+.\d+)", re.IGNORECASE)
    result = regex.findall(out)
    print result[0]
    return result[0]

if __name__=='__main__':
    ping('www.g.cn')
